<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="chapter05.css">
    <title>嵌套路由</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
    <h1>嵌套路由.</h1>
    <p>
        <router-link to="/user/张少平">张小三</router-link>
        <router-link to="/user/李光临">李小四</router-link>
    </p>
    <router-view></router-view>
</div>
<script>
    const user = {
        template: `
            <div>
                <h3>我的大名叫：{{$route.params.name}}</h3>
                <p>
                    <router-link to="profile">头像</router-link>
                    <router-link to="contact">联系人</router-link>
                </p>
                <router-view></router-view>
            </div>
        `
    };
    const profile = {
        template: '<p>{{$route.params.name}}头像</p>'
    };
    const contact = {
        template: '<p>联系人</p>'
    };

    const router = new VueRouter({
        routes: [
            {
                path: '/user/:name',
                component: user,
                children: [
                    {
                        // 当 /user/:name/profile 匹配成功，
                        // UserProfile 会被渲染在 User 的 <router-view> 中
                        path: 'profile',
                        component: profile
                    },
                    {
                        // 当 /user/:name/posts 匹配成功
                        // UserPosts 会被渲染在 User 的 <router-view> 中
                        path: 'contact',
                        component: contact
                    }
                ]
            }
        ]
    });

    new Vue({
        el: '#app',
        router: router
    });
</script>
</body>
</html>